<?php
class Link extends Element{

	private $authorizedElements = array("Image","Text");
	
	private $href;
	
	private $name;
	
	function __construct($href, $name){
		parent::__construct($this->authorizedElements);
		$this->href = str_replace('é','%C3%A90',$href);
		$this->name = $name;
	}
	
	function is_ancre($url){
		return  false;
	}
	
	function __toString(){
		
		$text = '<a';
		if(!empty($this->href)){$text.=' href ="'.$this->href.'"';}
		if(!empty($this->name)){$text.=' name="'.$this->name.'"';}
		$text.='>';
		
		$image = -1;
		
		foreach($this->elements as $elem){
			if (get_class($elem) == 'Image'){
				$image = $elem->get_num();
				$text .= $elem->toString(false);
			}else{
				$text .= $elem->__toString();
			}
		}
		$text.='</a>';
		
		if ($image != -1){
			$size = getimagesize($_SESSION['images'][$image]);
			if ($size[0] > 50){
				$text .= '<br />Ajouter un filtre &agrave; l\'image<br />';
				$text .= '<select onchange="document.getElementById(\'image_' . $image . '\').src =\'enhanceImage.php?image=' . $image . '&filtre=\' + this.value + \'\'"'; 
				$text .= ';>';
				$text .= '<option value="none">Aucun filtre</option>';
				$text .= '<option value="negate">Couleurs invers&eacute;es</option>';
				$text .= '<option value="gris">Niveau de gris</option>';
				$text .= '<option value="contour">Contour</option>';
				$text .= '</select>';
			}
		}
		
		return $text;
	}
}
?>